<?php 
include ORG_PATH . "/Smarty/Smarty.class.php";
class SmartyView{
	private static $smarty = NULL;
	
	public function __consrtuct(){
		if(!is_null(self::$smarty)) return;
		$smarty = new Smarty();
		$smarty->template_dir = APP_VIEW_PATH . '/' . CONTROLLER;
		$smarty->compile_dir = APP_COMPILE_PATH;
		$smarty->cache_dir = APP_CACHE_PATH;
		$smarty->caching = C('CACHE_ON');
		$smarty->cache_lifetime = C('CACHE_TIME');
		$smarty->left_delimiter = C('LEFT_DELIMITER');
		$smarty->right_delimiter = C('RIGHT_DELIMITER');
		$smarty->register_block("nocache", "nocache", false);
		
		//保存smarty对象到静态属性中
		self::$smarty = $smarty;	
	}
	/**
	 * 分配变量
	 */
	protected function assign($var,$value){
		self::$smarty->assign($var,$value);
	}
	/**
	 * 载入模板
	 */
	protected function display(){
		$path = APP_VIEW_PATH . '/' . CONTROLLER . '/' . ACTION . '.html';
		if(is_file($path)){
			self::$smarty->display($path);
		}else{
			halt($path . ' 模板找不到');
		}
	}
}
